unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IniFiles;

type
  TForm3 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Label1: TLabel;
    Edit2: TEdit;
    Label2: TLabel;
    GroupBox2: TGroupBox;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    Edit3: TEdit;
    Label3: TLabel;
    GroupBox3: TGroupBox;
    CheckBox3: TCheckBox;
    Edit4: TEdit;
    Label4: TLabel;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    Edit5: TEdit;
    Edit6: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    Edit7: TEdit;
    Label7: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox5Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

uses Unit1;

{$R *.dfm}

procedure LoadSettingsFromIni;
var
  Ini: TINIFile;
begin
  Ini := TINIFile.Create(Form1.Dir + 'settings.ini');
  Form1.ConnPort := Ini.ReadInteger('common', 'connport', 606);
  Form1.asConnAddress := Ini.ReadString('common', 'connaddress', '127.0.0.1');
  Form1.bUseEvilCompression := (Ini.ReadString('common', 'compression', 'false')
    = 'true');
  Form1.bUseEvilCompression_CPU := Form1.bUseEvilCompression;

  Form1.bUseIPTOFU := (Ini.ReadString('common', 'iptofumd5', 'false') = 'true');
  Form1.bUseTORTRUST := (Ini.ReadString('common', 'tortrust', 'false')
    = 'true');

  Form1.bExtThreadsVisualization :=
    (Ini.ReadString('visuals', 'extthreads', 'false') = 'true');
  Form1.dwShowTime := Ini.ReadInteger('visuals', 'showtime', 1000);
  Form1.dwSocketsTimeOut := Ini.ReadInteger('common', 'timeout', 1000);

  Form1.asTorIP := Ini.ReadString('common', 'torserver', '127.0.0.1');
  Form1.wTorPort := Ini.ReadInteger('common', 'torport', 9050);

  Form1.iMaxCPUUsage := Ini.ReadInteger('common', 'maxcpuusage', 100);

  Ini.Free;
end;
procedure TForm3.Button1Click(Sender: TObject);
begin
  close;
end;

procedure LoadVisualsFromSettings;
begin
  Form3.Edit1.Text := IntToStr(Form1.ConnPort);
  Form3.CheckBox1.Checked := Form1.bExtThreadsVisualization;
  Form3.CheckBox3.Checked := Form1.bUseEvilCompression;
  Form3.CheckBox4.Checked := Form1.bUseIPTOFU;
  Form3.CheckBox5.Checked := Form1.bUseTORTRUST;

  Form3.Edit5.Enabled := Form3.CheckBox5.Checked;
  Form3.Edit6.Enabled := Form3.CheckBox5.Checked;
  Form3.Edit7.Enabled := Form3.CheckBox3.Checked;

  Form3.Edit4.Text := IntToStr(Form1.dwSocketsTimeOut);
  Form3.Edit3.Enabled := Form3.CheckBox1.Checked;
  Form3.Edit3.Text := IntToStr(Form1.dwShowTime);
  Form3.Edit7.Text := IntToStr(Form1.iMaxCPUUsage);
  if Form1.asConnAddress = '0' then
    Form3.CheckBox2.Checked := true
  else
  begin
    Form3.CheckBox2.Checked := false;
    Form3.Edit2.Text := Form1.asConnAddress;
  end;
end;

procedure TForm3.Button2Click(Sender: TObject);
var
  Ini: TIniFile;
begin
{  if StrToInt(Edit3.Text) < 1000 then
    Edit3.Text := '1000';

  if (StrToInt(Edit7.Text) > 100) or (StrToInt(Edit7.Text) < 0) then
    Edit7.Text := '100';

  Ini := TIniFile.Create(Dir + 'settings.ini');
  Ini.WriteInteger('common', 'connport', StrToInt(Edit1.Text));

  Ini.WriteInteger('common', 'timeout', StrToInt(Edit4.Text));

  if CheckBox2.Checked then
    Ini.WriteString('common', 'connaddress', '0')
  else
    Ini.WriteString('common', 'connaddress', Edit2.Text);

  if CheckBox3.Checked then
    Ini.WriteString('common', 'compression', 'true')
  else
    Ini.WriteString('common', 'compression', 'false');

  if CheckBox4.Checked then
    Ini.WriteString('common', 'iptofumd5', 'true')
  else
    Ini.WriteString('common', 'iptofumd5', 'false');

  if CheckBox5.Checked then
    Ini.WriteString('common', 'tortrust', 'true')
  else
    Ini.WriteString('common', 'tortrust', 'false');

  Ini.WriteInteger('visuals', 'showtime', StrToInt(Edit3.Text));

  if CheckBox1.Checked then
    Ini.WriteString('visuals', 'extthreads', 'true')
  else
    Ini.WriteString('visuals', 'extthreads', 'false');

  Ini.WriteString('common', 'torserver', Edit5.Text);
  Ini.WriteInteger('common', 'torport', StrToInt(Edit6.Text));

  Ini.WriteInteger('common', 'maxcpuusage', StrToInt(Edit7.Text));

  Ini.Free;  }
end;

procedure TForm3.CheckBox2Click(Sender: TObject);
begin
  Edit2.Enabled := not CheckBox2.Checked;
end;

procedure TForm3.CheckBox3Click(Sender: TObject);
begin
  Form3.Edit7.Enabled := Form3.CheckBox3.Checked;
end;

procedure TForm3.CheckBox5Click(Sender: TObject);
begin
  Edit5.Enabled := CheckBox5.Checked;
  Edit6.Enabled := CheckBox5.Checked;
end;

procedure TForm3.CheckBox1Click(Sender: TObject);
begin
  Form3.Edit3.Enabled := Form3.CheckBox1.Checked;
end;

end.
